package com.jemframework.utils.stringformatter;

import java.util.HashMap;
import java.util.Map;

public class StringFormatterFactory {

  private static final StringFormatterFactory INSTANCE = new StringFormatterFactory();

  private Map<StringFormat, StringFormatter> mapping = new HashMap<StringFormat, StringFormatter>();

  public static StringFormatterFactory getInstance() {
    return INSTANCE;
  }

  private StringFormatterFactory() {
    init();
  }

  private void init() {
    mapping.put(StringFormat.XxxYyy, new XxxYyy_StringFormatter());
    mapping.put(StringFormat.xxxYyy, new xxxYyy_StringFormatter());
    mapping.put(StringFormat.XXX_YYY, new XXX_YYY_StringFormatter());
    mapping.put(StringFormat.xxxyyy, new xxxyyy_StringFormatter());
  }

  public StringFormatter getStringFormatter(StringFormat aStringFormat) {

    StringFormatter theStringFormatter = mapping.get(aStringFormat);

    if (theStringFormatter == null) {
      throw new IllegalArgumentException("Unknown string format: " + aStringFormat);
    }

    return theStringFormatter;
  }
}
